package site

import (
	"github.com/playwright-community/playwright-go"

	"torler.com/qingyue/common/model"
	"torler.com/qingyue/common/types"
)

var parsers = []SiteParser{}

func init() {
	parsers = append(parsers, &Site1Parser{})
	parsers = append(parsers, &Site2Parser{})
	parsers = append(parsers, &Site3Parser{})
	parsers = append(parsers, &Site4Parser{})
}

func GetParserBySiteId(siteId types.SourceId) SiteParser {
	for _, parser := range parsers {
		if parser.GetSiteInfo().Id == siteId {
			return parser
		}
	}
	return nil
}
func GetAllParser() []SiteParser {
	return parsers
}

// SiteParser NovelParser
type SiteParser interface {
	// 获取站点信息
	GetSiteInfo() *SiteInfo

	// 最近更新小说解析器
	ParseLastUpdate(page playwright.Page) ([]*model.LastestCBook, error)

	// 最近更新小说url
	GetLastUpdateUrl() string

	// 最近更新章节的列表选择器
	GetLastUpdateSelector() types.Selector

	// 小说信息和章节列表的解析器
	ParseBookInfo(page playwright.Page) (*model.RawBook, error)

	// 小说url
	GetBookInfoUrl(originBookId types.OriginId) string

	// 章节内容解析器
	ParseChapter(page playwright.Page) (string, error)

	// 章节url
	GetChapterUrl(oBookId, oChapterId types.OriginId) string

	//章节内容的selector
	GetChapterSelector() types.Selector
}
